using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using PropertyManagementFeatures.FeatureCode;
using Microsoft.SharePoint.Administration;

namespace PropertyManagementFeatures
{
    class TimerJobFeature : SPFeatureReceiver
    {
        const string JOB_NAME = "ViewingPromptTimerJob";

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSite site = (SPSite) (properties.Feature.Parent);
            foreach (SPJobDefinition job in site.WebApplication.JobDefinitions) 
            {
                if (job.Name == JOB_NAME)
                   job.Delete();
            }

            ViewingPromptTimerJob timeJob = new ViewingPromptTimerJob(JOB_NAME, site.WebApplication);

            SPMinuteSchedule schedule = new SPMinuteSchedule();
            schedule.BeginSecond = 0;
            schedule.EndSecond = 59;
            schedule.Interval = 1;

            timeJob.Schedule = schedule;
            timeJob.Update();

        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPSite site = (SPSite)(properties.Feature.Parent);
            foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
            {
                if (job.Name == JOB_NAME)
                    job.Delete();
            } 
        }

        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {           
        }

        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {  
        }
    }
}
